home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_024 / conquest / conqtf.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  177 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "structs.h"
  4. #include "vars.h"
  5.  
  6.  
  7. make_tf()
  8. {
  9.         char task; 
  10.         int tf_num; 
  11.         boolean error; 
  12.         int new_tf;
  13.         printf("ew tf- from tf:");
  14.         get_char(&task);
  15.         cle3r_left();
  16.         tf_num = task-'A'+1;
  17.         error= (tf_num<1) || (tf_num>26);
  18.         if ( ! error ) error= ( tf[player][tf_num].eta!=0) ||
  19.             (tf[player][tf_num].dest==0);
  20.         if ( error  ) {
  21.                 error_message();
  22.                 printf("  !illegal tf");
  23.         }
  24.         else if ( tf[player][tf_num].blasting ) {
  25.                 error = true;
  26.                 error_message();
  27.                 printf(" !Tf is blasting a planet     ");
  28.         }
  29.         else {
  30.                 point(1,19);
  31.                 split_tf(&tf_num,&new_tf);
  32.                 point(1,20);
  33.                 pr3nt_tf(new_tf);
  34.                 point(1,21);
  35.                 pr3nt_tf(tf_num);
  36.         };
  37. }
  38.  
  39.  
  40. split_tf(Tf2num, New2tf)
  41. int *Tf2num, *New2tf;
  42. {
  43.         int tf_num, new_tf;
  44.         char ships; 
  45.         int x,y,n_ships;
  46.         int ind; 
  47.         char iline[81];
  48.         new_tf = *New2tf;  
  49.         tf_num = *Tf2num;
  50.         get_tf(player,&new_tf,tf[player][tf_num].dest);
  51.         tf_stars[tf[player][tf_num].dest][player]++;
  52.         printf(" ships:");
  53.         point(8,y_cursor);
  54.         get_line(iline,&ind,false);
  55.         get_token(iline,&ind,&n_ships,&ships);
  56.         if ( ships==' ' ) { /*entire fleet*/
  57.                 tf[player][new_tf].s=tf[player][tf_num].s;
  58.                 tf[player][new_tf].t=tf[player][tf_num].t;
  59.                 tf[player][new_tf].c=tf[player][tf_num].c;
  60.                 tf[player][new_tf].b=tf[player][tf_num].b;
  61.                 tf[player][tf_num].s=0;
  62.                 tf[player][tf_num].t=0;
  63.                 tf[player][tf_num].c=0;
  64.                 tf[player][tf_num].b=0;
  65.         } 
  66.         else {
  67.                 do {
  68.                         switch ( ships ) {
  69.                         case 'T': 
  70.                                 if ( tf[player][tf_num].t < n_ships )
  71.                                         n_ships= tf[player][tf_num].t;
  72.                                 tf[player][tf_num].t=tf[player][tf_num].t-n_ships;
  73.                                 tf[player][new_tf].t=tf[player][new_tf].t+n_ships;
  74.                                 break;
  75.                         case 'S': 
  76.                                 if ( tf[player][tf_num].s <n_ships )
  77.                                         n_ships=tf[player][tf_num].s;
  78.                                 tf[player][tf_num].s=tf[player][tf_num].s-n_ships;
  79.                                 tf[player][new_tf].s=tf[player][new_tf].s+n_ships;
  80.                                 break;
  81.                         case 'C': 
  82.                                 if ( tf[player][tf_num].c < n_ships )
  83.                                         n_ships=tf[player][tf_num].c;
  84.                                 tf[player][tf_num].c=tf[player][tf_num].c-n_ships;
  85.                                 tf[player][new_tf].c=tf[player][new_tf].c+n_ships;
  86.                                 break;
  87.                         case 'B': 
  88.                                 if ( tf[player][tf_num].b < n_ships )
  89.                                         n_ships=tf[player][tf_num].b;
  90.                                 tf[player][tf_num].b=tf[player][tf_num].b-n_ships;
  91.                                 tf[player][new_tf].b=tf[player][new_tf].b+n_ships;
  92.                                 break;
  93.                         default:
  94.                                 error_message();
  95.                                 printf("  ! Illegal field %c",ships);
  96.                         }; /*switch (*/
  97.                         get_token(iline,&ind,&n_ships,&ships);
  98.                 } 
  99.                 while (ships != ' ');
  100.         };
  101.         x= tf[player][tf_num].x; 
  102.         y=tf[player][tf_num].y;
  103.         zero_tf(player,tf_num);
  104.         zero_tf(player,new_tf);
  105.         on_board(x,y);
  106.         *Tf2num = tf_num; 
  107.         *New2tf = new_tf;
  108. }
  109.  
  110. join_tf()
  111. {
  112.         char tf1,tf2; 
  113.         int tf1n,tf2n,ind,value;
  114.         char iline[81];
  115.         printf("oin tfs:");
  116.         ind = 1;
  117.         get_line(iline,&ind,true);
  118.         cle3r_left();
  119.         get_token( iline,& ind,& value,& tf1);
  120.         tf1n=tf1-'A'+1;
  121.         if ( (tf1n<1) || (tf1n>26) ) {
  122.                 error_message();
  123.                 printf("  ! illegal tf %c",tf1);
  124.         }
  125.         else if ( (tf[player][tf1n].eta)>0 ) {
  126.                 error_message();
  127.                 printf("  !tf%c is not in normal space ", tf1);
  128.         }
  129.         else if ( tf[player][tf1n].dest==0 ) {
  130.                 error_message();
  131.                 printf("  !nonexistent tf");
  132.         }
  133.         else if ( tf[player][tf1n].blasting ) {
  134.                 error_message();
  135.                 printf("  !Tf is blasting a planet    ");
  136.         }
  137.         else {
  138.                 get_token(iline,&ind,&value,&tf2);
  139.                 while ( tf2!=' ' ) {
  140.                         tf2n = tf2-'A'+1;
  141.                         if ( (tf2n<1) || (tf2n>26) ) {
  142.                                 error_message();
  143.                                 printf("  !illegal tf %c",tf2);
  144.                         }
  145.                         else if ( tf2n == tf1n) {
  146.                                 error_message();
  147.                                 printf("!Duplicate tf %c",tf2);
  148.                         }
  149.                         else if ( (tf[player][tf2n].dest == 0 ) ) {
  150.                                 error_message();
  151.                                 printf("!Nonexistant TF%c",tf2);
  152.                         }
  153.                         else if ( (tf[player][tf2n].x!=tf[player][tf1n].x) ||
  154.                             (tf[player][tf2n].y!= tf[player][tf2n].y) ) {
  155.                                 error_message();
  156.                                 printf("  !tf%c bad location", tf2);
  157.                         }
  158.                         else if ( tf[player][tf2n].eta !=0 ) {
  159.                                 error_message();
  160.                                 printf("  !tf%c is not in normal space ", tf2);
  161.                         }
  162.                         else if ( tf[player][tf2n].blasting ) {
  163.                                 error_message();
  164.                                 printf(" !Tf%c is blasting a planet    ", tf2);
  165.                         }
  166.                         else {
  167.                                 joinsilent(player,&tf[player][tf1n],&tf[player][tf2n]);
  168.                         };
  169.                         get_token(iline,&ind,&value,&tf2);
  170.                 };
  171.                 on_board(tf[player][tf1n].x,tf[player][tf1n].y);
  172.                 point(1,19);
  173.                 pr3nt_tf(tf1n);
  174.         };
  175. }
  176.  
  177.